function s(){
    let tr = document.querySelectorAll('#table tr');

    let all = document.querySelector("#all");
    let allnum = 0;

    for (let i = 0; i < tr.length; i++){
        //console.log("单价");
        //console.log(tr[i].children[2].children[0].innerHTML);
        //console.log("数量");
        //console.log(tr[i].children[3].children[0].value);
        //console.log("小计");
        //console.log(tr[i].children[4].children[0]);
        var price = tr[i].children[2].children[0].innerHTML;
        var num = tr[i].children[3].children[0].value;
        var total = tr[i].childern[4].childern[0].innerHTML = price * num;

        console.log(total);
        allnum += total
    }

    console.log(allnum);
    all.innerHTML = allnum.toFixed(2)
}
s();
let num_all = document.querySelectorAll('#table .num');
for(let j = 0; j < num_all.length; j++){
    num_all[j].addEventListener('change',s)
}

let del_all = document.querySelectorAll('#table .del');
for(let k = 0; k < del_all.length; k++){
    del_all[k].addEventListener('click',function(){
        console.log(this.parentNode.parentNode.parentNode);
        console.log(this.parentNode.parentNode);
        this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);

        s()
    })
}



var ipt = document.querySelector("#ipt");
var btn = document.querySelector("#btn");
var list = document.querySelector("#list");
btn.addEventListener('click',function(){
    var span = document.createElement('span');
    var spanText = document.createTextNode(ipt.value);
    span.appendChild(spanText);
    var button = document.createElement('button');
    var buttonText = document.createTextNode('删除');
    button.appendChild(buttonText);

    button.addEventListener('click',function(){
        console.log(this.parentNode);
        list.removeChild(this.parentNode)
    });


    var li =  document.createElement('li');
    li.appendChild(span);
    li.appendChild(button);
    console.log(li);
    list.appendChild(li);
})
